package com.japp.manager.web;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.japp.base.BaseAction;
import com.japp.manager.bean.QuantizaTionBean;
import com.japp.manager.service.QuantizaTionService;
import com.japp.sys.bean.SelectBean;
import com.japp.sys.mapper.DpMapper;
import com.japp.tools.common.Common;
import com.japp.tools.common.JappLog;
/**
 * 研究报告
 * @author Administrator
 *
 */
@Scope("prototype")
@Controller
public class QuantizaTionAction extends BaseAction<QuantizaTionBean> {

	private static final long serialVersionUID = -5677670163048708848L;
	@Autowired
	private QuantizaTionService quantizaTionService;
	@Autowired
	private DpMapper dpMapper;
	private QuantizaTionBean quantizaTion = new QuantizaTionBean();
	private Map<String, String> map = null;
	
	/**
	 * 查询研究报告
	 * @return
	 */
	public String queryQuantizaTion(){
		String power = session.getAttribute("u_power").toString();
		String dpid = session.getAttribute("userltd").toString();
		//String dpcode = session.getAttribute("userltdcode").toString();
		String usercode = session.getAttribute("u_code").toString();
		//部门
		if("2".equals(power)){
			quantizaTion.setQ_submit_dpid(dpid);
		//业务员
		}else if("3".equals(power)){
			quantizaTion.setQ_submit_ucode(usercode);
		}
		try {
			List<SelectBean> list = dpMapper.queryDpSelectAll();		//部门
			json_val = Common.formtSelectToJson(list);
		} catch (Exception e) {
			JappLog.log.error("查询部门或转换Json错误",e);
		}
		page = quantizaTionService.getPage(page, quantizaTion);
		return SUCCESS;
	}
	/**
	 * 查看
	 * @return
	 */
	public String findQuantizaTionView(){
		if(quantizaTion.getQ_id()!=0){
			quantizaTion = quantizaTionService.findQuantizaTionById(quantizaTion.getQ_id());
			obj_date = quantizaTion.getDates();
			obj_cdate = quantizaTion.getCdates();
		}
		return "quantizaTionView";
	}
	/**
	 * 欲新增 以及更新 
	 * @return quantizaTionView quantizaTionDetil
	 */
	public String findQuantizaTionDetil(){
		if(quantizaTion.getQ_id()!=0){
			quantizaTion = quantizaTionService.findQuantizaTionById(quantizaTion.getQ_id());
			obj_date = quantizaTion.getDates();
			obj_cdate = quantizaTion.getCdates();
		}
		return "quantizaTionEdit";
	}
	/**
	 * 删除
	 * @return
	 */
	public void deleteQuantizaTionById(){
		int rel = quantizaTionService.deleteQuantizaTion(keys);
		if(rel>0){
			result = "删除成功!";
		}else {
			result = "删除失败!";
		}
		wPrint(result);
	}
	/**
	 * 更新
	 * @return
	 */
	public void updateQuantizaTionById(){
		quantizaTion.setQ_submit_date(obj_date+obj_cdate);
		quantizaTion.setDates(obj_date);
		quantizaTion.setCdates(obj_cdate);
		int rel = quantizaTionService.updateQuantizaTion(quantizaTion);
		if(rel>0){
			result = String.valueOf(quantizaTion.getQ_id());
		}else {
			result = "error";
		}
		wPrint(result);
	}
	/**
	 * 新增
	 */
	public void insertQuantizaTionById(){
		quantizaTion.setQ_submit_date(obj_date+obj_cdate);
		quantizaTion.setDates(obj_date);
		quantizaTion.setCdates(obj_cdate);
		int rel = quantizaTionService.insertQuantizaTion(quantizaTion);
		if(rel>0&&quantizaTion.getQ_id()!=0){
			result = ""+quantizaTion.getQ_id();
		}else {
			result = "0";
		}
		wPrint(result);
	}
	public QuantizaTionBean getQuantizaTion() {
		return quantizaTion;
	}
	public void setQuantizaTion(QuantizaTionBean quantizaTion) {
		this.quantizaTion = quantizaTion;
	}
	public Map<String, String> getMap() {
		return map;
	}
	public void setMap(Map<String, String> map) {
		this.map = map;
	}
	
	
}

